import 'package:aero_frisbee/gen/assets.gen.dart';
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';

class AfAboutScreen extends StatefulWidget {
  const AfAboutScreen({Key? key}) : super(key: key);
  @override
  AfAboutScreenState createState() => AfAboutScreenState();
}

class AfAboutScreenState extends State<AfAboutScreen> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading: GestureDetector(
          behavior: HitTestBehavior.opaque,
          onTap: () {
            Navigator.of(context).maybePop();
          },
          child: Align(
            alignment: Alignment.centerLeft,
            child: Padding(
              padding: const EdgeInsets.only(
                left: 20,
              ),
              child: Assets.icons.iconMineBack.image(width: 25),
            ),
          ),
        ),
        title: const Text(
          'About',
          style: TextStyle(
            color: Color(0xff404040),
            fontWeight: FontWeight.normal,
            fontSize: 16,
          ),
          textAlign: TextAlign.center,
          overflow: TextOverflow.ellipsis,
          maxLines: 1,
        ),
      ),
      body: SingleChildScrollView(
        scrollDirection: Axis.vertical,
        child: Column(
          children: [
            const SizedBox(
              height: 45,
            ),
            const Align(
              alignment: Alignment.topCenter,
              child: Text(
                'AeroFrisbee',
                style: TextStyle(
                  color: Color(0xff202020),
                  fontWeight: FontWeight.w600,
                  fontSize: 22,
                ),
                textAlign: TextAlign.center,
                overflow: TextOverflow.ellipsis,
                maxLines: 1,
              ),
            ),
            const SizedBox(
              height: 50,
            ),
            const AfAboutRowItem(
              title: 'Version',
              isShowValue: true,
            ),
            GestureDetector(
              behavior: HitTestBehavior.opaque,
              onTap: () {
                launchUrl(
                  Uri.parse(
                    "http://h5.heeru.xyz/termConditions.html",
                  ),
                  mode: LaunchMode.inAppWebView,
                );
              },
              child: const AfAboutRowItem(
                title: 'Terms and Conditons',
              ),
            ),
            GestureDetector(
              behavior: HitTestBehavior.opaque,
              onTap: () {
                launchUrl(
                  Uri.parse("http://h5.heeru.xyz/privacyPolicy.html"),
                  mode: LaunchMode.inAppWebView,
                );
              },
              child: const AfAboutRowItem(
                title: 'Privacy Policy',
              ),
            ),
            // GestureDetector(
            //   behavior: HitTestBehavior.opaque,
            //   onTap: () {
            //     InAppReview.instance.requestReview();
            //   },
            //   child: const AfAboutRowItem(
            //     title: 'Rate Us',
            //   ),
            // ),
          ],
        ),
      ),
    );
  }

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  void didUpdateWidget(AfAboutScreen oldWidget) {
    super.didUpdateWidget(oldWidget);
  }

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
  }
}

class AfAboutRowItem extends StatelessWidget {
  const AfAboutRowItem(
      {Key? key, required this.title, this.isShowValue = false})
      : super(key: key);

  final String title;
  final bool isShowValue;

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        color: const Color(0xffF7F8FA),
        borderRadius: BorderRadius.circular(12),
      ),
      margin: const EdgeInsets.symmetric(horizontal: 32, vertical: 10),
      padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 12),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Text(
            title,
            style: const TextStyle(
              color: Color(0xff000000),
              fontWeight: FontWeight.normal,
              fontSize: 16,
            ),
            textAlign: TextAlign.left,
            overflow: TextOverflow.ellipsis,
            maxLines: 1,
          ),
          Visibility(
            visible: isShowValue,
            child: Text(
              '1.0.0',
              style: TextStyle(
                color: const Color(0xff000000).withOpacity(0.3),
                fontWeight: FontWeight.normal,
                fontSize: 14,
              ),
              textAlign: TextAlign.center,
              overflow: TextOverflow.ellipsis,
              maxLines: 1,
            ),
          )
        ],
      ),
    );
  }
}
